import 'package:bt_dsp_88/model/model_extension.dart';

import 'model.dart';

///每个通道的折线图颜色
const List<int> hex_line_list = [
  0xFFE93827,
  0xFF0000FF,
  0xFF7AF74C,
  0XFFFF00FF,
  0xFFFFFF00,
  0xFFFFFFFF,
  0xFF00FFFF,
  0xFFD2691E
];

///信号频率
const sign_freq_list = [
  20,
  25,
  32,
  40,
  50,
  63,
  80,
  100,
  125,
  160,
  200,
  250,
  315,
  400,
  500,
  630,
  800,
  1000,
  1250,
  1600,
  2000,
  2500,
  3150,
  4000,
  5000,
  6300,
  8000,
  10000,
  12500,
  16000,
  20000
];

final List<List<int>> effect_data = [
  [-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 2, 2, 1, 0, 0, 0, 0, -1, -1, -1, -1],

  ///
  [8, 8, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 3, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0],
  [5, 6, 7, 5, 3, 1, 3, 4, 4, 6, 4, 2, 0, -1, -3, 0, 1, 2, 3, 4, 5, 6, 7, 5, 4, 6, 7, 6, 5, 4, 4],
  [6, 5, 5, 4, 3, 2, 1, 1, 0, 0, 0, 1, 1, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3],
  [-4, -4, -4, -4, -4, -4, -3, -2, -2, -2, -1, 2, 3, 4, 4, 6, 7, 9, 9, 7, 5, 4, 2, 1, 0, -1, -2, -2, -3, -3, -3],
  [7, 6, 5, 4, 5, 6, 7, 8, 9, 9, 8, 6, 4, 2, 0, 0, -1, -2, -3, -4, -2, -1, 0, 1, 2, 3, 2, 1, 0, -1, -2]
];

///初始化一个全局的管理类
GlobalModel globalModel = GlobalModel(
  '',
  enable: false,
  ch_list: List.generate(8, ($0) {
    ChannelModel ch = initCH($0);

    ///默认第一个通道是选中状态
    ch.select = $0 == 0;

    return ch;
  }),
);

///默认group
final GroupModel default_group = GroupModel(
    ch1: ChannelModel(name: '', hex_line: 0xFFFFFFFF, 0, enable: false),
    ch2: ChannelModel(name: '', hex_line: 0xFFFFFFFF, 0, enable: false));

///初始化后，默认通道
final ChannelModel default_ch = initCH(10);

///默认信号通道
final SignModel default_sign = SignModel(20, '20', 0, enable: false);

///默认滤波类型
List<PassType> defualt_type_list = [
  PassType('Bessel', 12, slopeList: [12, 24, 36, 48]),
  PassType('Link-R', 12, slopeList: [12, 24, 36, 48]),
  PassType('Butter-W', 12, slopeList: [12, 24, 36, 48])
];

///初始化通道
ChannelModel initCH(int num) {
  return ChannelModel(num > 8 ? 0 : num + 1,
      name: num > 8 ? '' : 'CH${num + 1}',
      hex_line: num > 8 ? 0xFFFFFFFF : hex_line_list[num],
      high_pass: Passmodel('High Pass', true, 20, enable: false, type: defualt_type_list[0].copy),
      low_pass: Passmodel('Low Pass', false, 20000, enable: false, type: defualt_type_list[0].copy),
      input_list: List.filled(8, 0),
      // select: num == 0,
      enable: false,
      input_assign_list: List.generate(8, ($0) => $0 == num ? num + 1 : 0).toList(),
      input_custom_list: List.filled(8, 0),
      sign_list: sign_freq_list.asMap().entries.map(($0) {
        return SignModel($0.value, '${$0.value}', $0.key, enable: false, select: $0 == 20);
      }).toList());
}
